import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Team {
    String name; // 队名
    int matches; // 比赛场数
    int wins;    // 胜场数
    int draws;   // 平局数
    int losses;  // 负场数
    int goalsFor; // 进球数
    int goalsAgainst; // 失球数
    int points;  // 积分

    public Team(String name) {
        this.name = name;
        this.matches = 0;
        this.wins = 0;
        this.draws = 0;
        this.losses = 0;
        this.goalsFor = 0;
        this.goalsAgainst = 0;
        this.points = 0;
    }

    public void updateStats(int scored, int conceded) {
        this.matches++;
        this.goalsFor += scored;
        this.goalsAgainst += conceded;
        if (scored > conceded) {
            this.wins++;
            this.points += 3;
        } else if (scored == conceded) {
            this.draws++;
            this.points += 1;
        } else {
            this.losses++;
        }
    }

    public int getGoalDifference() {
        return goalsFor - goalsAgainst;
    }
}

public class FootballLeague {

    public static void main(String[] args) {
        // 初始化队伍
        List<Team> teams = new ArrayList<>();
        teams.add(new Team("广州队"));
        teams.add(new Team("上海队"));
        teams.add(new Team("北京队"));
        teams.add(new Team("深圳队"));

        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("请输入比赛结果 (格式: 主队 客队 主队进球 客队进球)，输入“exit”退出：");
            String input = scanner.nextLine();
            if (input.equals("exit")) break;

            String[] parts = input.split(" ");
            if (parts.length != 4) {
                System.out.println("输入格式有误，请重新输入！");
                continue;
            }

            String homeTeamName = parts[0];
            String awayTeamName = parts[1];
            int homeGoals = Integer.parseInt(parts[2]);
            int awayGoals = Integer.parseInt(parts[3]);

            Team homeTeam = findTeam(teams, homeTeamName);
            Team awayTeam = findTeam(teams, awayTeamName);

            if (homeTeam == null || awayTeam == null) {
                System.out.println("队伍名称错误，请检查后重新输入！");
                continue;
            }

            homeTeam.updateStats(homeGoals, awayGoals);
            awayTeam.updateStats(awayGoals, homeGoals);

            teams.sort((t1, t2) -> {
                if (t2.points != t1.points) return t2.points - t1.points;
                if (t2.getGoalDifference() != t1.getGoalDifference()) return t2.getGoalDifference() - t1.getGoalDifference();
                return t2.goalsFor - t1.goalsFor;
            });

            System.out.println("最新积分榜：");
            System.out.printf("%-10s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s\n", "队名", "场次", "胜", "平", "负", "进球", "失球", "净胜", "积分");
            for (Team team : teams) {
                System.out.printf("%-10s %-5d %-5d %-5d %-5d %-5d %-5d %-5d %-5d\n",
                        team.name, team.matches, team.wins, team.draws, team.losses,
                        team.goalsFor, team.goalsAgainst, team.getGoalDifference(), team.points);
            }
        }
    }

    public static Team findTeam(List<Team> teams, String name) {
        for (Team team : teams) {
            if (team.name.equals(name)) {
                return team;
            }
        }
        return null;
    }
}
